package com.wgj.android.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.jiaai.xui.utils.XDensityUtils;
import com.jiaai.xui.view.widget.XToast;
import com.wgj.android.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ========================================
 * 作    者： 佳爱网络有限公司(wwww.jiaailove.com)
 * 版    本： 1.0
 * 创建日期：  2017/11/25
 * 描    述：  分组修改窗口
 * 修订历吏：
 * =========================================
 */
public class ModifyGroupDialog extends AppCompatDialogFragment  {
    private OnGroupListener groupListener;
    @BindView(R.id.groupEdit)
    EditText groupView;




    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
         Dialog dialog = new Dialog(getActivity(), R.style.dialog_setting);
        LayoutInflater inflater=LayoutInflater.from(getContext());
        View view=inflater.inflate(R.layout.add_group_dialog,null,false);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(view);
        ButterKnife.bind(this,view);
        dialog.setCanceledOnTouchOutside(false); // 外部点击取消
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window window = dialog.getWindow();
        window.setWindowAnimations(R.style.popupwindow_anim_style);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM; // 紧贴底部
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(lp);
        return dialog;
    }


    @OnClick(R.id.cancelBut) void onCancel(View view){
         dismiss();
    }

    @OnClick(R.id.complete) void onComplete(View view){
        if(groupView.length()==0){
            XToast.warning("请输入分组名称");
            return;
        }else{
            if(groupListener!=null){
                groupListener.addGroup(groupView.getEditableText().toString());
            }
            dismiss();
        }
    }


    public ModifyGroupDialog setGroupListener(OnGroupListener groupListener) {
        this.groupListener = groupListener;
        return this;
    }

    public  interface  OnGroupListener{
         void addGroup(String groupName);
    }
}
